package com.framework.web;

import com.baomidou.dynamic.datasource.toolkit.CryptoUtils;
import java.security.KeyPair;

/**
 * @author 龘鵺
 * @version 1.0
 * @className com.framework.web
 * @description 数据库加密生成类
 * https://www.jb51.net/program/3139275lc.htm
 * https://blog.csdn.net/m0_54355172/article/details/127915056
 * https://blog.csdn.net/weixin_38064520/article/details/118765887
 * https://blog.csdn.net/wangshuai6707/article/details/132469462
 * @datetime 2025-05-07 10:14:55
 */
public class DataSourceTestEns {
    public static void main(String[] args) throws Exception {
//        公钥: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAmhoFx7y2h5xWDAvaSkT3tuD+j9nP4Y1AagbR79go5aXu6saVFIJN4pP2p0AIEHThcL2y2A05jkc31o82dthoBQIDAQABAkBtcvwV//eYW7ZVuflhdJiH4EeNPgNCzIMqiwuCkQGDEPs/Py3ZXDNnavVorvmHgRPQVwKCfA4QHC5Qm7mENzYlAiEA2hR7LvUHmfzN85pnM6MW9njYtNGpaMWz366A3qRKjG8CIQC05aL9DS5fPxgR9Od4GWGeErZrsEgavn+hdCVSE1O0ywIgNZc84kAymwPF9Kwn2kekt/LghibTs7yJxFkUsCG9dB8CIBx6Lg9iHNO3rgVdpXa9oCVvUrJfPOqg5Jy5GQrzqfDDAiBic6Y96O3zsMPSzIOm/GH0RHvA73fzCZii6F3e5W9ztA==
//        私钥: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJoaBce8toecVgwL2kpE97bg/o/Zz+GNQGoG0e/YKOWl7urGlRSCTeKT9qdACBB04XC9stgNOY5HN9aPNnbYaAUCAwEAAQ==
//        String[] strings = CryptoUtils.genKeyPair(512);
//        System.out.println("公钥: " + strings[0]);
//        System.out.println("私钥: " + strings[1]);
//
//        // 生成密钥对
//        String publicKey = strings[0];
//        String privateKey = strings[1];

        String publicKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAmhoFx7y2h5xWDAvaSkT3tuD+j9nP4Y1AagbR79go5aXu6saVFIJN4pP2p0AIEHThcL2y2A05jkc31o82dthoBQIDAQABAkBtcvwV//eYW7ZVuflhdJiH4EeNPgNCzIMqiwuCkQGDEPs/Py3ZXDNnavVorvmHgRPQVwKCfA4QHC5Qm7mENzYlAiEA2hR7LvUHmfzN85pnM6MW9njYtNGpaMWz366A3qRKjG8CIQC05aL9DS5fPxgR9Od4GWGeErZrsEgavn+hdCVSE1O0ywIgNZc84kAymwPF9Kwn2kekt/LghibTs7yJxFkUsCG9dB8CIBx6Lg9iHNO3rgVdpXa9oCVvUrJfPOqg5Jy5GQrzqfDDAiBic6Y96O3zsMPSzIOm/GH0RHvA73fzCZii6F3e5W9ztA==";
        String privateKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJoaBce8toecVgwL2kpE97bg/o/Zz+GNQGoG0e/YKOWl7urGlRSCTeKT9qdACBB04XC9stgNOY5HN9aPNnbYaAUCAwEAAQ==";
        //启动配置 vm options
        //--publicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJoaBce8toecVgwL2kpE97bg/o/Zz+GNQGoG0e/YKOWl7urGlRSCTeKT9qdACBB04XC9stgNOY5HN9aPNnbYaAUCAwEAAQ==
        // 加密原始密码
        String encryptedPassword = CryptoUtils.encrypt(publicKey, "123456");
        String encryptedUsername = CryptoUtils.encrypt(publicKey, "root");
        String encryptedUrl = CryptoUtils.encrypt(publicKey, "jdbc:mysql://localhost:3306/demoframework?allowMultiQueries=true&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false");
        String password = CryptoUtils.decrypt(privateKey, encryptedPassword);
        String username = CryptoUtils.decrypt(privateKey, encryptedUsername);
        String url = CryptoUtils.decrypt(privateKey, encryptedUrl);
        System.out.println("encrypt url: " + encryptedUrl);
        System.out.println("encrypt Username: " + encryptedUsername);
        System.out.println("encrypt Password: " + encryptedPassword);
        System.out.println("decrypt url: " + url);
        System.out.println("decrypt Username: " + username);
        System.out.println("decrypt Password: " + password);
    }
}
